package com.easylinkin.linkappapi.safe.entity.vo;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.easylinkin.linkappapi.safe.dto.DangerousInfoDto;
import lombok.Data;

import java.util.Date;
import java.util.StringJoiner;

/**
 * @author zhengwen
 */
@Data
public class DangerousInfoExcelVo extends DangerousInfoVo{
    private String typeName;
    private String typeDescribeName;
    private String superDangerousName;
    private String planTime;

    private String actualStartTimeStr;

    private String actualEndTimeStr;

    private String programStateName;

    private String constructionStateName;

    public DangerousInfoExcelVo(DangerousInfoDto dto) {
        //String keyValue = "类别:typeName,危大工程名称:name,是否超危:superDangerousName,计划时间:planTime,实际开始时间:actualStartTimeStr,实际结束时间:actualEndTimeStr,工区责任人:workAreaResponsible,分包责任人:subAreaResponsible,责任分包单位:subResponsibleOrg,方案状态:programStateName,施工状态:constructionStateName";
        this.setName(dto.getName());
        //类别:typeName
        this.typeName = dto.getTypeInfo().getMemo();
        this.typeDescribeName = dto.getTypeDescribeInfo().getMemo();
        //0否，1是
        Integer superDangerous = dto.getSuperDangerous();
        if (superDangerous == null){
            this.superDangerousName = "未知";
        }else {
            if (superDangerous.intValue() == 0){
                this.superDangerousName = "否";
            }
            if (superDangerous.intValue() == 1) {
                this.superDangerousName = "是";
            }

        }

        String dateFmt = "yyyy/MM/dd";
        StringJoiner sj = new StringJoiner("-");
        Date planStartTime = dto.getPlanStartTime();
        Date planEndTime = dto.getPlanEndTime();
        if (planStartTime != null){
            sj.add(DateUtil.format(planStartTime,dateFmt));
        }
        if (planEndTime != null){
            sj.add(DateUtil.format(planEndTime,dateFmt));
        }
        this.planTime = sj.toString();

        this.actualStartTimeStr = DateUtil.format(dto.getActualStartTime(),dateFmt);
        this.actualEndTimeStr = DateUtil.format(dto.getActualEndTime(),dateFmt);

        if (CollectionUtil.isNotEmpty(dto.getWorkAreaResponsibleList())){
            StringJoiner wsj = new StringJoiner(",");
            dto.getWorkAreaResponsibleList().stream().forEach(w->{
                wsj.add(w.getNickname());
            });
            this.setWorkAreaResponsible(wsj.toString());
        }else {
            this.setWorkAreaResponsible("");
        }
        if (CollectionUtil.isNotEmpty(dto.getSubAreaResponsibleList())){
            StringJoiner wsj = new StringJoiner(",");
            dto.getSubAreaResponsibleList().stream().forEach(w->{
                wsj.add(w.getNickname());
            });
            this.setSubAreaResponsible(wsj.toString());
        }else {
            this.setSubAreaResponsible("");
        }

        if (CollectionUtil.isNotEmpty(dto.getSubResponsibleOrgList())){
            StringJoiner wsj = new StringJoiner(",");
            dto.getSubResponsibleOrgList().stream().forEach(w->{
                wsj.add(w.getName());
            });
            this.setSubResponsibleOrg(wsj.toString());
        }else {
            this.setSubResponsibleOrg("");
        }
        //方案状态，1未完成，2已完成
        Integer programState = dto.getProgramState();
        if (programState == null){
            this.programStateName = "未知";
        }else {
            if (programState.intValue() == 1){
                this.programStateName = "未完成";
            }
            if (programState.intValue() == 2){
                this.programStateName = "已完成";
            }
        }
        //施工状态，1未开工，2在施，3完工
        Integer constructionState = dto.getConstructionState();
        if (constructionState == null){
            this.constructionStateName = "未知";
        }else {
            if (constructionState.intValue() == 1){
                this.constructionStateName = "未开工";
            }
            if (constructionState.intValue() == 2){
                this.constructionStateName = "在施";
            }
            if (constructionState.intValue() == 3){
                this.constructionStateName = "完工";
            }
        }


    }
}
